package com.adc.douyu_assistant.utils;

import com.adc.douyu_assistant.entity.DanmuMessage;
import com.adc.douyu_assistant.service.DanmuMessageService;
import com.adc.douyu_assistant.service.impl.DanmuMessageServiceImpl;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author: yuhl
 * @Date: 2018/8/16 14:16
 * @Description:
 */
public enum Singleton {
    INSTANCE;

    public void sendHeartBeatToKeepAlive(Channel channel, long millis) {
        Thread thread = new Thread(new HeartBeat(channel, millis));
        thread.start();
    }

    class HeartBeat implements Runnable {
        private Channel channel;
        private long millis;

        public HeartBeat(Channel channel, long millis) {
            this.channel = channel;
            this.millis = millis;
        }

        public void run() {
            while (true) {
                try {
                    Thread.sleep(millis);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                channel.writeAndFlush(MessageConstractor.getMessage("type@=mrkl/"));
            }
        }
    }
}
